$(function() {
    var tuitionDetail_datagrid = $("#tuitionDetail_datagrid");
    var tuitionDetail_form = $("#tuitionDetail_form");
    var tuitionDetail_dialog = $("#tuitionDetail_dialog");
    //begin列表信息
    tuitionDetail_datagrid.datagrid({
        url: "/tuitionDetail/list",
        columns: [[
            {field: "xxx", checkbox: 'true'},
            {field: "id", title: "编号", width: 100,hidden:true},
            {field: "professionalstuent", title: "学员姓名", width: 100,formatter:function (value,row,index) {
                    return value?value.name :''
             }},
            {field: "billdate", title: "收款时间", width: 100},
            {field: "amountcollected", title: "收款金额", width: 100},

            {field: "grade", title: "班级", width: 100 ,formatter:function (value,row,index) {
                return value?value.name :''
            }},
            {field: "collectionsuser", title: "收款人", width: 100 ,formatter:function (value,row,index) {
                return value?value.username :''
            }},
            {field: "datadictionaryitem", title: "支付方式", width: 100 ,formatter:function (value,row,index) {
                return value?value.name :''
            } },
            {field: "receipts", title: "单据号", width: 100},
            {field: "remark", title: "备注", width: 100},
            {field: "market", title: "营销人员", width: 100 ,formatter:function (value,row,index) {
                return value?value.username :''
            }},
            {field: "unpaidamount", title: "未交金额", width: 100},
            {field: "state", title: "状态", width: 100 ,formatter:function (value,row,index) {
                    if(value == 0){
                        return '<font color="red">审核中</font>';
                    }else if(value == 1){
                        return '<font color="green">审核通过</font>';
                    }
             }}
        ]],
        fit: true,
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        striped: true,
        pageNumber:1,
        pageSize:10,
        pageList:[3,5,10,20],
        toolbar: "#tuitionDetail_tb"
    });
    //end列表信息

    //begin添加/编辑对话框
    tuitionDetail_dialog.dialog({
        width: 350,
        height: 400,
        buttons: "#tuitionDetail_bb",
        closed: true
    });
    //end添加/编辑对话框




    //begin处理功能方法的对象
    var obj = {
        //begin添加按钮
        add: function () {
            tuitionDetail_form.form("clear");
            tuitionDetail_dialog.dialog("setTitle", "添加收费");
            tuitionDetail_dialog.dialog("open");
            $('#tuitionDetailId').combobox({
                onChange: function (newValue, oldValue) {
                    if(newValue){

                    $.get("/tuition/selectTuitionStudentByprofessionStudent?professionStudentId="+newValue ,function(date){
                        $("#grade").combobox('setValue', date.grade.id);
                        $("#unpaidamount").textbox('setValue', date.unpaidaltuition);

                    })
                    }
                }
            });
        },
        //end添加按钮

        //begin查看按钮
        watch: function () {
            tuitionDetail_form.form("clear");
            tuitionDetail_dialog.dialog("setTitle", "收款查看查看");
            var row = tuitionDetail_datagrid.datagrid("getSelected");
            console.log(row);
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $("#refund_form :input").prop("readonly" ,true);
            if(row){
                $("#tuitionDetailId").combobox('setValue', row.professionalstuent.name);
                row["datadictionaryitem.id"] = row.datadictionaryitem.id;
                row["collectionsuser.id"] = row.collectionsuser.id;
                row["grade.id"] = row.grade.id;
                row["grade.id"] = row.grade.id;

            }
            //隐藏保存按钮
            /* $("#tuitionDetail_bb").hide();
            // 关闭窗口显示保存按钮
            tuitionDetail_dialog.dialog({
                onClose:function () {
                    $("#tuitionDetail_bb").show();
                }
            })*/
            tuitionDetail_dialog.dialog("setTitle", "收款查看");
            tuitionDetail_form.form("load", row);
            tuitionDetail_dialog.dialog("open");
            tuitionDetail_form.find("input").attr("readonly",true);
        },
        //end查看按钮



        //begin取消按钮
        cancel: function () {
            tuitionDetail_dialog.dialog("close");
        },
        //end取消按钮

        //begin保存按钮
        save: function () {
            var url = "/tuitionDetail/save"
            tuitionDetail_form.form("submit", {
                url: url,
                success: function (data) {
                    var data = $.parseJSON(data);
                    if (!data.success) {
                        $.messager.alert('温馨提示', data.msg);
                    } else {
                        $.messager.alert('温馨提示', "操作成功!");
                        tuitionDetail_dialog.dialog("close");
                        tuitionDetail_datagrid.datagrid("reload");
                    }
                }
            });

        },
        //end保存按钮

        //begin 审核按钮
        changeState: function (){
            var row = tuitionDetail_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $.messager.confirm('审核确认','想好后请点击确认？',function(r){
                if (r){
                    var url = "/tuitionDetail/changeState?id="+row.id;
                    $.get(url, function(data){

                        if (!data.success) {
                            $.messager.alert('温馨提示', data.msg);
                        } else {
                            $.messager.alert('温馨提示', "操作成功!");

                            tuitionDetail_datagrid.datagrid("reload");
                        }
                    });
                }
            });

        },
        //end 审核按钮





        // begin缴费记录高级查询操作
        query: function() {
            var keywords= $("#keywords").textbox("getValue");
            var beginDate= $("#beginDate").textbox("getValue");
            var endDate= $("#endDate").textbox("getValue");
            var geade= $("#geadeId").combobox("getValue");
            tuitionDetail_datagrid.datagrid("load",{
                keywords:keywords,
                beginDate:beginDate,
                endDate:endDate,
                geade:geade
            });
        },
        // 缴费记录高级查询操作 end


        //begin刷新按钮
        reload:function (){
            tuitionDetail_datagrid.datagrid("reload")
        }
        //end刷新按钮
    };
    //end处理功能方法的对象





    //begin处理功能方法对象,实际调用方法
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        obj[cmd]();
    });
    //end处理功能方法对象,实际调用方法

});


